#include <QCoreApplication>
//#include <QtSql>
#include <qDebug>
#include <iostream>
//#include "Conn.h"
#include "contemplation.h"
#include "search.h"
#include "objectid.h"

using namespace std;

int main(int argc, char *argv[])
{
 //   int half = 6;
    QCoreApplication a(argc, argv);
    Search search;
    cout << endl << "press enter to begin" << endl;
    cin.get();


    search.clearDatabase();
    cout << endl << endl << "Now I've cleared my mind, and re-initialized the system" << endl << endl;
    cin.get();



    string text = "entering adjectives organic, black, angry, white, brown, and cold";
    cout << endl << endl << text << endl << endl;
    cin.get();

    BaseObject organic = search.addNewWord("descriptive", "organic");
    BaseObject black = search.addNewWord("descriptive", "black");
    BaseObject brown = search.addNewWord("descriptive", "brown");
    BaseObject angry = search.addNewWord("descriptive", "angry");
    BaseObject white = search.addNewWord("descriptive", "white");
    BaseObject cold = search.addNewWord("descriptive", "cold");

    text = "entering wings, feathers, hair and paws";
    cout << endl << endl << text << endl << endl;
    cin.get();

    BaseObject wings = search.addNewWord("concrete", "wings");
    BaseObject feathers = search.addNewWord("concrete", "feathers");
    BaseObject hair = search.addNewWord("concrete", "hair");
    BaseObject paws = search.addNewWord("concrete", "paws");

    text = "entering objects animals, bird, raven, dove, chicken, penguin, sparrow and turkey, bear, polar, grizzly, ursus, and putting them into the tree.";
    cout << endl << endl << text << endl << endl;
    cin.get();

    BaseObject animal = search.addNewWord("concrete", "animal");
    BaseObject bird = search.addNewWord("concrete", "bird");
    BaseObject raven = search.addNewWord("concrete", "raven");
    BaseObject dove = search.addNewWord("concrete", "dove");
    BaseObject chicken = search.addNewWord("concrete", "chicken");
    BaseObject penguin = search.addNewWord("concrete", "penguin");
    BaseObject sparrow = search.addNewWord("concrete", "sparrow");
    BaseObject turkey = search.addNewWord("concrete", "turkey");
    BaseObject bear = search.addNewWord("concrete", "bear");
    BaseObject polar = search.addNewWord("concrete", "polar");
    BaseObject grizzly = search.addNewWord("concrete", "grizzly");
    BaseObject ursus = search.addNewWord("concrete", "ursus");

    search.addRelationshipInfo("isarelationship", bird, animal);
    search.addRelationshipInfo("isarelationship", raven, bird);
    search.addRelationshipInfo("isarelationship", dove, bird);
    search.addRelationshipInfo("isarelationship", chicken, bird);
    search.addRelationshipInfo("isarelationship", penguin, bird);
    search.addRelationshipInfo("isarelationship", sparrow, bird);
    search.addRelationshipInfo("isarelationship", turkey, bird);
    search.addRelationshipInfo("isarelationship", bear, animal);
    search.addRelationshipInfo("isarelationship", grizzly, bear);
    search.addRelationshipInfo("isarelationship", ursus, bear);
    search.addRelationshipInfo("isarelationship", polar, bear);

    text = "Now we say that animals are organic, and create 10 of each bird and bear with various characteristics.";
    cout << endl << endl << text << endl << endl;
    cin.get();
    cout << "Working on it, hold on!";

    search.addRelationshipInfo("object_to_description", animal, organic);

    ObjectID tempObject;

    for (int i = 0; i < 10; i++)
    {
        tempObject = search.addNewObject(raven);
        //cout << "adding a raven" << endl;
        search.addRelationshipInfo("object_to_contains", tempObject, wings);
        search.addRelationshipInfo("object_to_contains", tempObject, feathers);
        search.addRelationshipInfo("object_to_description", tempObject, black);
    }

    ObjectID ravenObject = tempObject;



    //cin.get();
    tempObject = search.addNewObject(raven);
    search.addRelationshipInfo("object_to_contains", tempObject, wings);
    search.addRelationshipInfo("object_to_contains", tempObject, feathers);
    search.addRelationshipInfo("object_to_description", tempObject, white);

    tempObject = search.addNewObject(raven);
    search.addRelationshipInfo("object_to_contains", tempObject, wings);
    search.addRelationshipInfo("object_to_contains", tempObject, feathers);
    search.addRelationshipInfo("object_to_description", tempObject, white);

    tempObject = search.addNewObject(raven);
    search.addRelationshipInfo("object_to_contains", tempObject, wings);
    search.addRelationshipInfo("object_to_contains", tempObject, feathers);
    search.addRelationshipInfo("object_to_description", tempObject, white);


    for (int i = 0; i < 10; i++)
    {
        tempObject = search.addNewObject(dove);
        search.addRelationshipInfo("object_to_contains", tempObject, wings);
        search.addRelationshipInfo("object_to_contains", tempObject, feathers);
        search.addRelationshipInfo("object_to_description", tempObject, white);
    }

    for (int i = 0; i < 10; i++)
    {
        tempObject = search.addNewObject(chicken);
        search.addRelationshipInfo("object_to_contains", tempObject, wings);
        search.addRelationshipInfo("object_to_contains", tempObject, feathers);
    }

    for (int i = 0; i < 10; i++)
    {
        tempObject = search.addNewObject(penguin);
        search.addRelationshipInfo("object_to_contains", tempObject, wings);
        search.addRelationshipInfo("object_to_contains", tempObject, feathers);
    }

    for (int i = 0; i < 10; i++)
    {
        tempObject = search.addNewObject(sparrow);
        search.addRelationshipInfo("object_to_contains", tempObject, wings);
        search.addRelationshipInfo("object_to_contains", tempObject, feathers);
    }

    for (int i = 0; i < 10; i++)
    {
        tempObject = search.addNewObject(turkey);
        search.addRelationshipInfo("object_to_contains", tempObject, wings);
        search.addRelationshipInfo("object_to_contains", tempObject, feathers);
    }

    ObjectID grizzlyObject;
    for (int i = 0; i < 10; i++)
    {
        tempObject = search.addNewObject(grizzly);
        //cout << "adding a grizzly" << endl;
        search.addRelationshipInfo("object_to_contains", tempObject, paws);
        search.addRelationshipInfo("object_to_contains", tempObject, hair);
        search.addRelationshipInfo("object_to_description", tempObject, brown);
    }
    grizzlyObject = tempObject;

    for (int i = 0; i < 10; i++)
    {
        tempObject = search.addNewObject(ursus);
        search.addRelationshipInfo("object_to_contains", tempObject, paws);
        search.addRelationshipInfo("object_to_contains", tempObject, hair);
        search.addRelationshipInfo("object_to_description", tempObject, black);
    }

    for (int i = 0; i < 10; i++)
    {
        tempObject = search.addNewObject(polar);
        search.addRelationshipInfo("object_to_contains", tempObject, paws);
        search.addRelationshipInfo("object_to_contains", tempObject, hair);
        search.addRelationshipInfo("object_to_description", tempObject, white);
    }

//    cout << endl << endl << endl << "and the tables say" << endl << endl;

//    cout << endl << "heres the words table" << endl << endl;

//    search.displayTable("words");

//    cout << endl << "heres the rel_inductive_tally table" << endl << endl;

//    search.displayTable("rel_inductive_tally");



    cout << endl << endl;

//    qDebug() << "grizzly table " << grizzly.table << " and id is " << grizzly.id;
//    qDebug() << "raven table " << raven.table << " and id is " << raven.id;
//    qDebug() << "animal table " << animal.table << " and id is " << animal.id;
//    qDebug() << "bear table " << bear.table << " and id is " << bear.id;
//    qDebug() << "bird table " << bird.table << " and id is " << bird.id;
//    qDebug() << "feather table " << feathers.table << " and id is " << feathers.id;
//    qDebug() << "wings table " << wings.table << " and id is " << wings.id;
//    qDebug() << "hair table " << hair.table << " and id is " << hair.id;
//    qDebug() << "paws table " << paws.table << " and id is " << paws.id;
//    qDebug() << "brown table " << brown.table << " and id is " << brown.id;
//    qDebug() << "black table " << black.table << " and id is " << black.id;
//    qDebug() << "white table " << white.table << " and id is " << white.id;




//    cout << endl << endl << "contains table: " << endl << endl;

//    search.displayTable("rel_object_to_contains");
//    cout << endl << endl;

//    cout << endl << endl << "description table: " << endl << endl;

//    search.displayTable("rel_object_to_description");
//    cout << endl << endl;


    cout << "Does a grizzly have hair?";
    cin.get();
    QString response = search.wordCharacteristic(grizzly,"rel_object_to_contains", hair);
    cout << endl << endl;
    qDebug() << response;
    cout << endl << endl;

    cout << "Does a raven have wings?" << endl;
    cin.get();
    response = search.wordCharacteristic(raven,"rel_object_to_contains", wings);
    cout << endl << endl;
    qDebug() << response;
    cout << endl << endl;

    cout << "Does a chicken have paws?" << endl;
    cin.get();
    response = search.wordCharacteristic(chicken,"rel_object_to_contains", paws);
    cout << endl << endl;
    qDebug() << response;
    cout << endl << endl;

    cout << "Is a raven black?" << endl;
    cin.get();
    response = search.wordCharacteristic(raven,"rel_object_to_description", black);
    cout << endl << endl;
    qDebug() << response;
    cout << endl << endl;

    cout << "Does a bear have hair?";
    cin.get();
    response = search.wordCharacteristic(bear,"rel_object_to_contains", hair);
    cout << endl << endl;
    qDebug() << response;
    cout << endl << endl;

    cout << "Does a bird have feathers?";
    cin.get();
    response = search.wordCharacteristic(bird,"rel_object_to_contains", feathers);
    cout << endl << endl;
    qDebug() << response;
    cout << endl << endl;

    cout << endl << endl << "Lets enter a new relationship" << endl << endl;
    cin.get();

    cout << endl << endl << "The list of current tables:" << endl << endl;
    search.showTables();
    cin.get();

    cout << endl << endl << "entering a new relationship, relationshipA";

    ObjectID fred;
    ObjectID harry;
            search.addRelationshipInfo("relationshipA", fred, harry);

    cout << endl << endl << "Now the list of tables:" << endl << endl;
    search.showTables();
    cin.get();


//    search.displayTable("rel_inductive_tally");


    //search.displayTable("rel_inductive_tally");



    //cout << "QList<BaseObject> bases;" << endl << "bases.push_back(search.addNewWord(\"person\", \"person\"));" << end << "bases.push_back(search.addNewWord(\"descriptive\",\"female\"));" << endl <<endl;


//    QList<BaseObject> basesf;
//    basesf.push_back(search.addNewWord("person", "person"));
//    basesf.push_back(search.addNewWord("descriptive","female"));

//    QList<BaseObject> basesm;
//    basesm.push_back(search.addNewWord("person", "person"));
//    basesm.push_back(search.addNewWord("descriptive","male"));

//    QList<ObjectID> men1;
//    QList<ObjectID> women1;

//    QList<ObjectID> men2;
//    QList<ObjectID> women2;

//    QList<ObjectID> men3;
//    QList<ObjectID> women3;

//    QList<ObjectID> men4;
//    QList<ObjectID> women4;


//    for(int i = 0; i < half; i++)
//    {
//        men1.push_back(search.addNewObject(basesm));
//    }


//    for(int i = 0; i < half; i++)
//    {
//        women1.push_back(search.addNewObject(basesf));
//    }

//    for(int i = 0; i < half; i++)
//    {
//        search.addRelationshipInfo("married", men1[i], women1[i]);
//        search.addRelationshipInfo("married", women1[i], men1[i]);
//        for(int j = 0; j < 3; j++)
//        {
//            ObjectID tempm = search.addNewObject(basesm);
//            men2.push_back(tempm);
//            search.addRelationshipInfo("son", tempm, women1[i]);
//            search.addRelationshipInfo("son", tempm, men1[i]);
//            search.addRelationshipInfo("mother", women1[i], tempm);
//            search.addRelationshipInfo("father", men1[i], tempm);
//        }
//        for(int j = 0; j < 3; j++)
//        {
//            ObjectID tempf = search.addNewObject(basesf);
//            women2.push_back(tempf);
//            search.addRelationshipInfo("son", tempf, women1[i]);
//            search.addRelationshipInfo("son", tempf, men1[i]);
//            search.addRelationshipInfo("mother", women1[i], tempf);
//            search.addRelationshipInfo("father", men1[i], tempf);
//        }


//        for(int j = (men2.size() - 3); j < men2.size(); j++)
//        {
//            search.addRelationshipInfo("son", men2[j], women1[i]);
//            search.addRelationshipInfo("son", men2[j], men1[i]);
//            search.addRelationshipInfo("father",  men1[i], men2[j]);
//            search.addRelationshipInfo("mother", women1[i], men2[j]);
//            search.addRelationshipInfo("daughter", women2[j], women1[i]);
//            search.addRelationshipInfo("daughter", women2[j], men1[i]);
//            search.addRelationshipInfo("father",  men1[i], women2[j]);
//            search.addRelationshipInfo("mother", women1[i], women2[j]);
//            for(int k = (women2.size() - 3); k < women2.size(); k++)
//            {
//                search.addRelationshipInfo("brother", men2[j], women2[k]);
//                search.addRelationshipInfo("sister", women2[k], men2[j]);
//            }
//        }
//    }


//    QList<ObjectID> men1;

//    QList<ObjectID> women1;









    cout << endl << endl << "end of test" << endl;
    cin.get();


    qDebug() << "End of Program" << endl;
    return a.exec();
}








